/*
  Copyright © 2010  Vinícius dos Santos Oliveira

      This file is part of Touché.

      Touché is free software: you can redistribute it and/or modify
      it under the terms of the GNU Lesser General Public License as published
      by the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU Lesser General Public License for more details.

      You should have received a copy of the GNU Lesser General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */

#ifndef STAGE_H
#define STAGE_H

#include "widgets/pushbuttonitem.h"
#include "widgets/draggabletogglebutton.h"
#include "toucheelement.h"
#include <QGraphicsView>
#include <QScopedPointer>

class VoidItem;

namespace Touche {
    class StageActor;

    class Stage : public QGraphicsObject
    {
        static QScopedPointer<Stage> m_instance;
        Stage(QGraphicsItem *parentItem);

        Stage(const Stage &);             // not defined
        Stage & operator=(const Stage &); // not defined

        Q_OBJECT

        QList<StageActor *> elements;
        VoidItem *m_items;
        QPointF pressedAt;

    protected:
        virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
        virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
        virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);

    public:
        static Stage * makeInstance(QGraphicsItem *parentItem = 0);
        static Stage * getInstance();
        ~Stage();

        virtual QRectF boundingRect() const;
        virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *);
        void addToGroup(Element *element);

        static QSizeF elementSize();
        static QPointF elementHiddenPos();
        static QPointF elementInitialPos();

        void setElementSize(const QSizeF &size);
        void setElementHiddenPos(const QPointF &pos);
        void setElementInitialPos(const QPointF &pos);
        void setElementTrashPos(const QPointF &pos);

    private slots:
        void onElementDeleted(QObject *element);

    signals:
        //sinais úteis para a comunicação dos itens com Scene,
        //que fará a comunicação com o módulo de colaboração
        void elementChanged(Element *);
        void elementDeleted(Element *);
    };

} // namespace Touche

#endif // STAGE_H
